package com.atguigu.gulimall.search.controller;

import com.atguigu.gulimall.search.service.SearchService;
import com.atguigu.gulimall.search.vo.SearchParam;
import com.atguigu.gulimall.search.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {
    @Autowired
    private SearchService searchService;
    @GetMapping("/list.html")
    public String list(SearchParam searchParam, Model model, HttpServletRequest request){
        searchParam.setNavLink(request.getQueryString());
        SearchResultVo searchResultVo = searchService.search(searchParam);

        model.addAttribute("result",searchResultVo);
        return "list";
    }

    @RequestMapping("/test")
    @ResponseBody
    public Object test(SearchParam searchParam, Model model){
        SearchResultVo searchResultVo = searchService.search(searchParam);
        return searchResultVo;
    }

    @RequestMapping("/test1")
    @ResponseBody
    public String test(){
        //SearchResultVo searchResultVo = searchService.search(searchParam);
        return "111111111111111";
    }

}
